package com.shop.service.impl;

import com.shop.common.result.Result;
import com.shop.common.result.util.ResultModel;
import com.shop.entity.ProductPicDo;
import com.shop.mapper.ProductPicDoMapper;
import com.shop.mapper.ext.ProductPicDoMapperExt;
import com.shop.service.ProductPicService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.vo.SelectProductPicVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 商品图片信息表 服务实现类
 * </p>
 *
 * @author 靳 旺
 * @since 2021-01-29
 */
@Service
public class ProductPicServiceImpl extends ServiceImpl<ProductPicDoMapper, ProductPicDo> implements ProductPicService {

    @Autowired
    private ProductPicDoMapperExt productPicDoMapperExt;

    @Override
    public ResultModel selectProductPic(SelectProductPicVo selectProductPicVo) throws Exception {
        List<ProductPicDo> productPicDos = productPicDoMapperExt.selectCommodityBatchIds(selectProductPicVo.getFkCommodityId());
        Map<Long, List<ProductPicDo> > longListMap = productPicDos.stream().collect(Collectors.groupingBy(ProductPicDo::getFkCommodityId));
        return Result.successResultModel(longListMap);
    }
}
